package com.xiaoma.verbal.web.admin;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.xiaoma.tpo.utils.Pager;
import com.xiaoma.verbal.dto.QuestionVo;
import com.xiaoma.verbal.service.ForecastService;
import com.xiaoma.verbal.service.QuestionService;

@Controller
@RequestMapping("/test/fctquestion")
public class FctQuestionManagementAct {
	@Autowired
	private QuestionService questionService;
	@Autowired
	private ForecastService forecastService;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> list(Integer fid, ModelMap model) {
		// 当前页
		Map<String, Object> result = new HashMap<String, Object>();
		List<QuestionVo> list = this.forecastService.findFQubyId(fid);
		result.put("content", list);
		return result;

	}

	@RequestMapping(value = "/import", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> importData(@RequestParam(value = "excelData", required = false) MultipartFile file, String fileType, HttpServletRequest request, ModelMap model) {
		// 当前页
		Map<String, Object> result = new HashMap<String, Object>();

		InputStream fis = null;
		Integer[] status = null;
		PrintWriter out = null;
		JSONObject json = new JSONObject();
		try {
			fis = file.getInputStream();
			int version = 2007;
			if (fileType != null && fileType.length() > 0 && fileType.equals("xls")) {
				version = 2003;
			}
			status = forecastService.importData(version, fis);
		} catch (Exception e) {
			e.printStackTrace();
			// status = 3;
			json.put("msg", e.getMessage());
		}
		result.put("result", status);

		return result;

	}

	
}
